package cn.tonyandmoney.baidu.asr.model;

import java.util.Iterator;

import cn.tonyandmoney.baidu.asr.entity.NluResult;

/**
 * 过滤器
 */
public abstract class AsrFilter {

    protected void filter(NluResult result, Iterator<AsrFilter> filters) {
        Boolean isGoOn = false;
        try {
            isGoOn = doFilter(result);
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            if (!isGoOn) afterFilter(result, filters);
        }
    }

    protected abstract boolean doFilter(NluResult result);

    protected void afterFilter(NluResult result, Iterator<AsrFilter> filters) {
        if (!filters.hasNext()) return;
        AsrFilter filter = filters.next();
        filter.filter(result, filters);
    }

}
